package com.ebelter.btcomlib.models.bluetooth.products.temperature2;

import android.content.Context;
import com.ebelter.btcomlib.models.bluetooth.base.BaseManager;
import com.ebelter.btcomlib.models.bluetooth.bean.ProductStyle;
import com.ebelter.btcomlib.models.bluetooth.interfaces.IDataReadWriteCallback;
import com.ebelter.btcomlib.models.bluetooth.products.temperature2.interfaces.Temperature2MesureResult;
import com.ebelter.btcomlib.utils.BytesUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;


/**
 * 额耳温枪
 */
public class Temperature2Manager extends BaseManager{

    private static final String TAG = "EarTemperatureManager";



    private Temperature2BytesAnalysis mTemperature2BytesAnalysis;
    private Temperature2BytesMake mTemperature2BytesMake;




    public Temperature2Manager(Context mContext) {
        super(mContext, ProductStyle.THERMOMETER2, Temperature2Constant.Temperature2_SERVICE_UUID,
                new String[]{Temperature2Constant.Temperature2_WRITE_UUID},
                new String[]{Temperature2Constant.Temperature2_READ_UUID1},
                true,500);

        mTemperature2BytesAnalysis = new Temperature2BytesAnalysis();
        mTemperature2BytesMake = new Temperature2BytesMake();


        mServiceGatt.setIDataReadWriteCallback(new IDataReadWriteCallback() {
            @Override
            public void onCharacteristicChanged(byte[] data) {
                LogUtils.i(TAG, "Temperature2Manager--IDataReadWriteCallback-onCharacteristicChanged--读到-" + BytesUtils.bytes2HexStr(data));
                mTemperature2BytesAnalysis.resultAnalysis(data);
            }

            @Override
            public void writeData(byte[] data) {
                // LogUtils.i(TAG,"ScaleBlue--IDataReadWriteCallback-writeData--写入-"+ Arrays.toString(data));
            }
        });
    }


    //设置回调接口
    public void setTemperature2MeasureCallback(Temperature2MesureResult temperature2MesureResult) {
        mTemperature2BytesAnalysis.setTemperature2MeasureCallback(temperature2MesureResult);
    }


    //发送一条接收成功的ack
    public void sendReceiveSuccessACK() {
        addSendMsg(mTemperature2BytesMake.getReceiveSuccessAck());
    }

    public void setUnitC() {
        addSendMsg(mTemperature2BytesMake.setUnitC());
    }

    public void setUnitF() {
        addSendMsg(mTemperature2BytesMake.setUnitF());
    }

    //设置连接成功的蓝牙名字
    public void setConnectedBluetoothName(String name) {
        if (mTemperature2BytesAnalysis!=null)mTemperature2BytesAnalysis.setConnectedBluetoothName(name);
    }
}
